.class public Lcom/melesta/expansions/ExpansionsManager;
.super Ljava/lang/Object;
.source "ExpansionsManager.java"


# static fields
.field static instance:Lcom/melesta/expansions/ExpansionsManager;


# instance fields
.field private expansions:Ljava/util/List;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/List",
            "<",
            "Lcom/melesta/expansions/IEngineExpansion;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method protected constructor <init>(Landroid/content/Context;)V
    .locals 9
    .parameter "context"

    .prologue
    .line 24
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 42
    new-instance v6, Ljava/util/LinkedList;

    invoke-direct {v6}, Ljava/util/LinkedList;-><init>()V

    iput-object v6, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    .line 25
    invoke-virtual {p1}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v6

    sget v7, Lcom/melesta/engine/R$array;->expansions:I

    invoke-virtual {v6, v7}, Landroid/content/res/Resources;->getStringArray(I)[Ljava/lang/String;

    move-result-object v0

    .local v0, arr$:[Ljava/lang/String;
    array-length v4, v0

    .local v4, len$:I
    const/4 v3, 0x0

    .local v3, i$:I
    :goto_0
    if-ge v3, v4, :cond_1

    aget-object v2, v0, v3

    .line 26
    .local v2, expansion:Ljava/lang/String;
    const-string v6, "java"

    new-instance v7, Ljava/lang/StringBuilder;

    invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

    const-string v8, "load expansion "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/melesta/engine/Log;->d(Ljava/lang/String;Ljava/lang/String;)V

    .line 27
    const/4 v5, 0x0

    .line 29
    .local v5, o:Ljava/lang/Object;
    :try_start_0
    invoke-static {v2}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/Class;->newInstance()Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/IllegalAccessException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/lang/InstantiationException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_2

    move-result-object v5

    .line 37
    .end local v5           #o:Ljava/lang/Object;
    :goto_1
    instance-of v6, v5, Lcom/melesta/expansions/IEngineExpansion;

    if-eqz v6, :cond_0

    .line 38
    check-cast v5, Lcom/melesta/expansions/IEngineExpansion;

    invoke-virtual {p0, v5}, Lcom/melesta/expansions/ExpansionsManager;->addExpansion(Lcom/melesta/expansions/IEngineExpansion;)Z

    .line 25
    :cond_0
    add-int/lit8 v3, v3, 0x1

    goto :goto_0

    .line 30
    .restart local v5       #o:Ljava/lang/Object;
    :catch_0
    move-exception v1

    .line 31
    .local v1, e:Ljava/lang/IllegalAccessException;
    const-string v6, "java"

    new-instance v7, Ljava/lang/StringBuilder;

    invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

    const-string v8, "IllegalAccessException: "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v1}, Ljava/lang/IllegalAccessException;->getMessage()Ljava/lang/String;

    move-result-object v8

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/melesta/engine/Log;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_1

    .line 32
    .end local v1           #e:Ljava/lang/IllegalAccessException;
    :catch_1
    move-exception v1

    .line 33
    .local v1, e:Ljava/lang/InstantiationException;
    const-string v6, "java"

    new-instance v7, Ljava/lang/StringBuilder;

    invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

    const-string v8, "InstantiationException: "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v1}, Ljava/lang/InstantiationException;->getMessage()Ljava/lang/String;

    move-result-object v8

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/melesta/engine/Log;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_1

    .line 34
    .end local v1           #e:Ljava/lang/InstantiationException;
    :catch_2
    move-exception v1

    .line 35
    .local v1, e:Ljava/lang/ClassNotFoundException;
    const-string v6, "java"

    new-instance v7, Ljava/lang/StringBuilder;

    invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

    const-string v8, "ClassNotFoundException: "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v1}, Ljava/lang/ClassNotFoundException;->getMessage()Ljava/lang/String;

    move-result-object v8

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/melesta/engine/Log;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_1

    .line 40
    .end local v1           #e:Ljava/lang/ClassNotFoundException;
    .end local v2           #expansion:Ljava/lang/String;
    .end local v5           #o:Ljava/lang/Object;
    :cond_1
    return-void
.end method

.method public static getInstance(Landroid/content/Context;)Lcom/melesta/expansions/ExpansionsManager;
    .locals 1
    .parameter "context"

    .prologue
    .line 19
    sget-object v0, Lcom/melesta/expansions/ExpansionsManager;->instance:Lcom/melesta/expansions/ExpansionsManager;

    if-nez v0, :cond_0

    .line 20
    new-instance v0, Lcom/melesta/expansions/ExpansionsManager;

    invoke-direct {v0, p0}, Lcom/melesta/expansions/ExpansionsManager;-><init>(Landroid/content/Context;)V

    sput-object v0, Lcom/melesta/expansions/ExpansionsManager;->instance:Lcom/melesta/expansions/ExpansionsManager;

    .line 21
    :cond_0
    sget-object v0, Lcom/melesta/expansions/ExpansionsManager;->instance:Lcom/melesta/expansions/ExpansionsManager;

    return-object v0
.end method


# virtual methods
.method public addExpansion(Lcom/melesta/expansions/IEngineExpansion;)Z
    .locals 2
    .parameter "expansion"

    .prologue
    .line 45
    iget-object v1, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    monitor-enter v1

    .line 46
    :try_start_0
    iget-object v0, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    invoke-interface {v0, p1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 47
    invoke-interface {p1}, Lcom/melesta/expansions/IEngineExpansion;->onAddExpansion()V

    .line 48
    const/4 v0, 0x1

    monitor-exit v1

    .line 51
    :goto_0
    return v0

    .line 50
    :cond_0
    monitor-exit v1

    .line 51
    const/4 v0, 0x0

    goto :goto_0

    .line 50
    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public clear()V
    .locals 2

    .prologue
    .line 72
    iget-object v1, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    monitor-enter v1

    .line 73
    :try_start_0
    iget-object v0, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    invoke-interface {v0}, Ljava/util/List;->clear()V

    .line 74
    monitor-exit v1

    .line 75
    return-void

    .line 74
    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public fireActivityResult(Landroid/content/Context;IILandroid/content/Intent;)V
    .locals 3
    .parameter "context"
    .parameter "requestCode"
    .parameter "resultCode"
    .parameter "data"

    .prologue
    .line 92
    iget-object v2, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_0

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/melesta/expansions/IEngineExpansion;

    .line 93
    .local v0, exp:Lcom/melesta/expansions/IEngineExpansion;
    invoke-interface {v0, p1, p2, p3, p4}, Lcom/melesta/expansions/IEngineExpansion;->onActivityResult(Landroid/content/Context;IILandroid/content/Intent;)V

    goto :goto_0

    .line 95
    .end local v0           #exp:Lcom/melesta/expansions/IEngineExpansion;
    :cond_0
    return-void
.end method

.method public fireActivityStateChange(Lcom/melesta/expansions/ActivityState;Landroid/content/Context;Landroid/os/Handler;)V
    .locals 3
    .parameter "state"
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 66
    iget-object v2, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_0

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/melesta/expansions/IEngineExpansion;

    .line 67
    .local v0, exp:Lcom/melesta/expansions/IEngineExpansion;
    invoke-interface {v0, p1, p2, p3}, Lcom/melesta/expansions/IEngineExpansion;->onActivitySateChange(Lcom/melesta/expansions/ActivityState;Landroid/content/Context;Landroid/os/Handler;)V

    goto :goto_0

    .line 69
    .end local v0           #exp:Lcom/melesta/expansions/IEngineExpansion;
    :cond_0
    return-void
.end method

.method public free()V
    .locals 1

    .prologue
    .line 78
    invoke-virtual {p0}, Lcom/melesta/expansions/ExpansionsManager;->clear()V

    .line 79
    const/4 v0, 0x0

    sput-object v0, Lcom/melesta/expansions/ExpansionsManager;->instance:Lcom/melesta/expansions/ExpansionsManager;

    .line 80
    return-void
.end method

.method public getExpansion(Ljava/lang/Class;)Lcom/melesta/expansions/IEngineExpansion;
    .locals 3
    .parameter "type"

    .prologue
    .line 83
    iget-object v2, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :cond_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_1

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/melesta/expansions/IEngineExpansion;

    .line 84
    .local v0, exp:Lcom/melesta/expansions/IEngineExpansion;
    invoke-virtual {p1, v0}, Ljava/lang/Class;->isInstance(Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_0

    .line 88
    .end local v0           #exp:Lcom/melesta/expansions/IEngineExpansion;
    :goto_0
    return-object v0

    :cond_1
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public removeExpansion(Lcom/melesta/expansions/IEngineExpansion;)Z
    .locals 2
    .parameter "expansion"

    .prologue
    .line 55
    iget-object v1, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    monitor-enter v1

    .line 56
    :try_start_0
    iget-object v0, p0, Lcom/melesta/expansions/ExpansionsManager;->expansions:Ljava/util/List;

    invoke-interface {v0, p1}, Ljava/util/List;->remove(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 57
    invoke-interface {p1}, Lcom/melesta/expansions/IEngineExpansion;->onRemoveExpansion()V

    .line 58
    const/4 v0, 0x1

    monitor-exit v1

    .line 61
    :goto_0
    return v0

    .line 60
    :cond_0
    monitor-exit v1

    .line 61
    const/4 v0, 0x0

    goto :goto_0

    .line 60
    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method
